package com.bjc.chapter10;

import java.nio.ByteBuffer;
import java.util.ArrayList;

/**
 * 直接内存的OOM：OutOfMemoryError: Direct buffer memory
 */
public class BufferTest2 {

    //20m
    private static final int BUFFER = 1024*1024*20;

    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();

        int count = 0;
        try {
            while (true){
                ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER);
                list.add(byteBuffer);
                Thread.sleep(100);
                count++;
            }
        }catch (Exception e){
            System.out.println(count);
            e.printStackTrace();
        }
    }
}
